package de.tum.in.far.threedui.general;
import javax.media.j3d.Alpha;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.LineArray;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TransparencyAttributes;
import javax.media.j3d.TransparencyInterpolator;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;


public class VanishingLine extends BranchGroup{
	
	LineArray axes ;
	public VanishingLine(Point3f p1, Point3f p2)
	{

		setCapability(ALLOW_CHILDREN_WRITE);
		setCapability(ALLOW_CHILDREN_READ);
		
		
		Line line = new Line(p1, p2);
		TransparencyAttributes ta = new TransparencyAttributes();
		ta.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
		ta.setCapability(TransparencyAttributes.ALLOW_MODE_READ);
		ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
		ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
		ta.setTransparencyMode(TransparencyAttributes.FASTEST);
		
		Appearance app = new Appearance();
		app.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
		app.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
		app.setTransparencyAttributes(ta);
		line.setAppearance(app);
		
		Alpha alpha = new Alpha(1,3000);
		alpha.setStartTime(System.currentTimeMillis() + 100);
		TransparencyInterpolator tranI = new TransparencyInterpolator(alpha, ta, 0, 1);
		tranI.setSchedulingBounds(new BoundingSphere());
		addChild(line);
		addChild(tranI);
		
	}
	
	public VanishingLine(float px, float py, float pz, float qx, float qy, float qz)
	{
		this(new Point3f(px, py, pz), new Point3f(qx, qy, qz));
	}
	
	float getInRange(double n)
	{
		return (float) Math.min(1, n + 0.3);
	}
	
	

	public static BranchGroup asBranchGroup(VanishingLine cm)
	{
		BranchGroup gp = new BranchGroup();
		gp.addChild(cm);
		return gp;
	}
	
	public BranchGroup asBranchGroup()
	{
		BranchGroup gp = new BranchGroup();
		gp.addChild(this);
		return gp;
	}
	
}
